<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		function fakeQuest(num) {
			// 假装一个不定时的异步请求
			let timeout = parseInt(Math.random() * 1000);
			return new Promise((resolv, reject) => {
				setTimeout(() => {
					resolv({
						timeout,
						num
					})
				}, timeout);
			})
		}

		async function main() {
			let arr = [1, 2, 3, 4, 5, 6];

			// for (let key of arr) {
			// 	let result = await fakeQuest(key)
			// 	console.log(result);
			// }

			for (let key in arr) {
				let result = await fakeQuest(key)
				console.log(result);
			}

			// for (var i = 0; i < arr.length; i++) {
			// 	let result = await fakeQuest(i)
			// 	console.log(result);
			// }


			// let start = Promise.resolve()
			// arr.forEach(async (item, i) => {
			// 	start = new Promise(async (resolv, reject) => {
			// 		await start;
			// 		let result = await fakeQuest(i)
			// 		console.log(result)
			// 		resolv()

			// 	})
			// })

			// reduce
			// arr.reduce((pre, item, i) => {
			// 	return new Promise(async (resolv, reject) => {
			// 		await pre;
			// 		let result = await fakeQuest(i)
			// 		console.log(result)
			// 		resolv()
			// 	})
			// }, Promise.resolve())
		}

		main()
	</script>
</body>

</html>